import { createSlice } from "@reduxjs/toolkit"
import { log } from '../../configs/common'

const cache2Slice = createSlice({
  name: 'cache2',
  initialState: {},
  reducers: {
    setCache: (state, action) => {
        log('setCache')
        const { cacheKey, cacheContent } = action.payload
        if (cacheKey === undefined) {
          throw new Error('cacheKey不能是undefined')
        }
        if (cacheContent === undefined) {
          throw new Error('cacheContent不能是undefined')
        }
        state[cacheKey] = { ...state[cacheKey], ...cacheContent }
        return { ...state }
    },
    clearCache: (state, action) => {
        log('clearCache')
        return {}
    }
  }
})

export const {setCache, clearCache} = cache2Slice.actions

export default cache2Slice.reducer

